//
//  NKChangePasswordUserViewController.m
//  NewKY
//
//  Created by Dee on 2016/11/16.
//  Copyright © 2016年 Dee. All rights reserved.
//

#import "NKChangePasswordUserViewController.h"
#import <ZYKeyboardUtil.h>
@interface NKChangePasswordUserViewController ()<UITextFieldDelegate>

@property(nonatomic, strong) ZYKeyboardUtil *keyboardUtil;

@property (weak, nonatomic) IBOutlet UITextField *phoneTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;

@end

@implementation NKChangePasswordUserViewController

- (IBAction)changePasswordAction:(id)sender {
    
    //根据手机号码获取数据
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    
//    [userDefaults setObject:phone forKey:@"NOW_USER_PHONE"];
    
    NSString *phone = [userDefaults objectForKey:@"NOW_USER_PHONE"];
    
    [SVProgressHUD showInfoWithStatus:[@"当前用户:" stringByAppendingString:phone]];
    
    NSString *password = [userDefaults objectForKey:[@"password="stringByAppendingString:phone]];
    
    if(!password){
        
        [SVProgressHUD showErrorWithStatus:@"密码错误"];
        
    }else{
        
        [SVProgressHUD showSuccessWithStatus:@"修改成功"];
        
        //设置登录状态记录
//        [userDefaults setObject:@"1" forKey:@"USER_STATUS"];
        
//        [userDefaults setObject:phone forKey:@"NOW_USER_PHONE"];
        
//        [[self getLeftViewController].tableView reloadData];
        
        [[self getMainNavigation] showHomeViewController];
        
    }
    
    
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIColor *color = [UIColor grayColor];
    NSAttributedString *phoneAttr = [[NSAttributedString alloc]
                                     initWithString:@"原密码"
                                     attributes:@{NSForegroundColorAttributeName:color}];
    NSAttributedString *passwordAttr = [[NSAttributedString alloc]
                                        initWithString:@"新密码"
                                        attributes:@{NSForegroundColorAttributeName:color}];
    
    UIView *phoneLine=[[UIView alloc]initWithFrame:CGRectMake(0,self.phoneTextField.height-1, self.phoneTextField.width, 1)];
    phoneLine.backgroundColor=[UIColor lightGrayColor];
    
    
    UIView *passwordLine=[[UIView alloc]initWithFrame:CGRectMake(0,self.passwordTextField.height-1, self.passwordTextField.width, 1)];
    passwordLine.backgroundColor=[UIColor lightGrayColor];
    
    [self.phoneTextField addSubview:phoneLine];
    [self.passwordTextField addSubview:passwordLine];
    
    self.phoneTextField.attributedPlaceholder = phoneAttr;
    self.passwordTextField.attributedPlaceholder = passwordAttr;
    
    
    
    
    self.keyboardUtil = [[ZYKeyboardUtil alloc] init];
    __weak NKChangePasswordUserViewController *weakSelf = self;
    [_keyboardUtil setAnimateWhenKeyboardAppearAutomaticAnimBlock:^(ZYKeyboardUtil *keyboardUtil) {
        [keyboardUtil adaptiveViewHandleWithController:weakSelf adaptiveView:weakSelf.view, weakSelf.phoneTextField, weakSelf.passwordTextField, nil];
    }];
    
    
    self.phoneTextField.delegate = self;
    self.passwordTextField.delegate = self;
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


#pragma mark - delegate
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.phoneTextField resignFirstResponder];
    [self.passwordTextField resignFirstResponder];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [self.phoneTextField resignFirstResponder];
    [self.passwordTextField resignFirstResponder];
    return YES;
}



@end
